home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Programming / SWI / source / src / pl-incl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-18  |  56.2 KB  |  1,669 lines

  1. /*  $Id: pl-incl.h,v 1.103 1998/02/18 13:56:57 jan Exp $
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     See ../LICENCE to find out about your rights.
  5.     jan@swi.psy.uva.nl
  6.  
  7.     Purpose: SWI-Prolog general include file
  8. */
  9.  
  10. #ifndef _PL_INCLUDE_H
  11. #define _PL_INCLUDE_H
  12.  
  13. #ifdef __WIN32__
  14. #define MD         "config/win32.h"
  15. #define PLHOME       "c:/pl"
  16. #define DEFSTARTUP   ".plrc"
  17. #define ARCH         "i386-win32"
  18. #define C_LIBS         ""
  19. #define C_STATICLIBS ""
  20. #define C_CC         "cl"
  21. #define C_LDFLAGS    ""
  22. #else
  23. #include <parms.h>            /* pick from the working dir */
  24. #endif
  25.  
  26. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  27. First, include config.h or, if MD is  specified, this file.  This allows
  28. for -DMD="md-mswin.h"
  29. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  30.  
  31. #ifndef CONFTEST
  32. #ifdef MD
  33. #include MD
  34. #else
  35. #include <config.h>
  36. #endif
  37. #endif
  38.  
  39. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  40.               PROLOG SYSTEM OPTIONS
  41.  
  42. These are not really options normally.  They are there because I use  to
  43. add  new  features  conditional  using  #if ... #endif.  In many cases I
  44. leave them in for ducumentation purposes.   Notably  O_STRING  might  be
  45. handy for it someone wants to add a data type to the system.
  46.  
  47.   O_STRING
  48.       Include data type string.  This  feature  does  not  rely  on  any
  49.       system  feature.   It  hardly has any consequences for the system.
  50.       Because of its experimental nature it is optional.  The definition
  51.       of the predicates operating on strings might change.
  52.       (NOTE: Currently some of the boot files rely on strings. It is NOT
  53.       suggested to leave them out).
  54.   O_COMPILE_OR
  55.       Compile ->/2, ;/2 and |/2 into WAM.  This  no  longer  is  a  real
  56.       option.   the mechanism to handle cuts without compiling ;/2, etc.
  57.       has been taken out.
  58.   O_COMPILE_ARITH
  59.       Include arithmetic compiler (compiles is/2, >/2, etc. into WAM).
  60.   O_PROLOG_FUNCTIONS
  61.       Include evaluatable Prolog functions into the arithmetic module.
  62.   O_BLOCK
  63.       Include support for block/3, !/1, fail/1 and exit/2 in the VM.
  64.   O_LABEL_ADDRESSES
  65.       Means we can pick up the address of a label in  a function using
  66.       the var  = `&&label' construct  and jump to  it using goto *var;
  67.       This construct is known by the GNU-C compiler gcc version 2.  It
  68.       is buggy in gcc-2.0, but seems to works properly in gcc-2.1.
  69.   VMCODE_IS_ADDRESS
  70.       Can only  be set when  O_LABEL_ADDRESSES is  set.  It causes the
  71.       prolog  compiler  to put the  code  (=  label-) addresses in the
  72.       compiled Prolog  code  rather than the  virtual-machine numbers.
  73.       This speeds-up  the vm  instruction dispatching in  interpret().
  74.       See also pl-comp.c
  75. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  76.  
  77. #define PL_KERNEL        1
  78. #define O_COMPILE_OR        1
  79. #define O_SOFTCUT        1
  80. #define O_COMPILE_ARITH        1
  81. #define O_STRING        1
  82. #define O_PROLOG_FUNCTIONS    1
  83. #define O_BLOCK            1
  84. #define O_CATCHTHROW        1
  85. #define O_INLINE_FOREIGNS    1
  86. #define O_PCE            1    /* doesn't depend any longer */
  87. #define O_DEBUGGER        1
  88. #define O_INTERRUPT        1
  89. #define O_DESTRUCTIVE_ASSIGNMENT 1
  90. #define O_HASHTERM        1
  91. #define O_LIMIT_DEPTH        1
  92.  
  93. #ifndef DOUBLE_TO_LONG_CAST_RAISES_SIGFPE
  94. #ifdef __i386__
  95. #define DOUBLE_TO_LONG_CAST_RAISES_SIGFPE 1
  96. #endif
  97. #endif
  98.  
  99. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  100. On the MIPS, whether or not alignment can   be used appears to depend on
  101. the compilation flags. We play safe for   the  case the user changes the
  102. flags after running configure.
  103. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  104.  
  105. #if !defined(DOUBLE_ALIGNMENT) && defined(__mips__)
  106. #define DOUBLE_ALIGNMENT sizeof(double)
  107. #endif
  108.  
  109. #if MMAP_STACK || O_SHARED_MEMORY || HAVE_VIRTUAL_ALLOC
  110. #define O_DYNAMIC_STACKS 1        /* sparse memory management */
  111. #else
  112. #ifndef O_SHIFT_STACKS
  113. #define O_SHIFT_STACKS 1        /* use stack-shifter */
  114. #endif
  115. #endif
  116.  
  117. #ifndef O_LABEL_ADDRESSES
  118. #if __GNUC__ == 2
  119. #define O_LABEL_ADDRESSES    1
  120. #ifndef VMCODE_IS_ADDRESS
  121. #define VMCODE_IS_ADDRESS    1
  122. #endif
  123. #endif
  124. #endif
  125.  
  126. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  127. Runtime version.  Uses somewhat less memory and has no tracer.
  128. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  129.  
  130. #ifdef O_RUNTIME
  131. #undef O_PROFILE            /* no profiling */
  132. #undef O_DEBUGGER            /* no debugging */
  133. #undef O_READLINE            /* no readline too */
  134. #undef O_INTERRUPT            /* no interrupts too */
  135. #endif
  136.  
  137.  
  138. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  139. The macros below try to establish a common basis for various  compilers,
  140. so  we  can  write  most  of the real code without having to worry about
  141. compiler limits and differences.
  142.  
  143. The  current  version  has  prototypes  defined   for   all   functions.
  144. Unfortunately  there  are  still a lot of old compilers around and it is
  145. hard to write and maintain code that runs on both old and new compilers.
  146. This has worked on TURBO_C not very long ago.
  147. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  148.  
  149. #if (defined(__unix__) || defined(_AIX)) && !defined(unix)
  150. #define unix 1
  151. #endif
  152.  
  153. /* AIX requires this to be the first thing in the file.  */
  154. #ifdef __GNUC__
  155. # define alloca __builtin_alloca
  156. #else
  157. # if HAVE_ALLOCA_H
  158. #  include <alloca.h>
  159. # else
  160. #  ifdef _AIX
  161.  #pragma alloca
  162. #  else
  163. #   ifndef alloca /* predefined by HP cc +Olibcalls */
  164. void *alloca ();
  165. #   endif
  166. #  endif
  167. # endif
  168. #endif
  169.  
  170.  
  171. #if HAVE_XOS_H
  172. #include <xos.h>
  173. #endif
  174. #ifdef HAVE_UXNT_H
  175. #include <uxnt.h>
  176. #endif
  177.  
  178. #ifndef CONFTEST
  179. #include "pl-stream.h"
  180. #else
  181. #include <stdio.h>            /* for testing pl-save.c */
  182. #endif
  183.  
  184. #include <sys/types.h>
  185. #include <setjmp.h>
  186. #ifdef ASSERT_H_REQUIRES_STDIO_H
  187. #include <stdio.h>
  188. #endif /*ASSERT_H_REQUIRES_STDIO_H*/
  189. #include <assert.h>
  190. #include <stdlib.h>
  191. #include <string.h>
  192. #include <stddef.h>
  193. #include <stdarg.h>
  194.  
  195. #ifdef HAVE_SIGNAL
  196. #include <signal.h>
  197. #endif
  198. #ifdef HAVE_MALLOC_H
  199. #include <malloc.h>
  200. #endif
  201.  
  202. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  203. #include <string.h>
  204. /* An ANSI string.h and pre-ANSI memory.h might conflict.  */
  205. #if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
  206. #include <memory.h>
  207. #endif /* not STDC_HEADERS and HAVE_MEMORY_H */
  208. #else /* not STDC_HEADERS and not HAVE_STRING_H */
  209. #include <strings.h>
  210. /* memory.h and strings.h conflict on some systems.  */
  211. #endif /* not STDC_HEADERS and not HAVE_STRING_H */
  212.  
  213. #if OS2 && EMX
  214. #include <process.h>
  215. #include <io.h>
  216. #endif /* OS2 */
  217.  
  218. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  219. A common basis for C keywords.
  220. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  221.  
  222. #if __GNUC__ && !__STRICT_ANSI__
  223. #define HAVE_INLINE 1
  224. #define HAVE_VOLATILE 1
  225. #endif
  226.  
  227. #if !defined(HAVE_INLINE) && !defined(inline)
  228. #define inline
  229. #endif
  230.  
  231. #if defined(__GNUC__) && !defined(register)
  232. #define register
  233. #endif
  234.  
  235. #ifndef HAVE_VOLATILE
  236. #define volatile
  237. #endif
  238.  
  239.  
  240. #if __STRICT_ANSI__
  241. #undef TAGGED_LVALUE
  242. #endif
  243.  
  244. #if defined(__STRICT_ANSI__) || defined(NO_ASM_NOP)
  245. #define ASM_NOP { static int nop; nop++; }
  246. #endif
  247.  
  248. #define forwards static        /* forwards function declarations */
  249.  
  250. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  251. Booleans,  addresses,  strings  and other   goodies.   Note that  ANSI
  252. compilers have  `Void'.   This should  be  made part  of  the  general
  253. platform as well.
  254. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  255.  
  256. typedef int            bool;
  257. typedef double            real;
  258. typedef void *            Void;
  259.  
  260. #if __GNUC__ && !__STRICT_ANSI__
  261. #define LocalArray(t, n, s)    t n[s]
  262. #else
  263. #define LocalArray(t, n, s)    t *n = (t *) alloca((s)*sizeof(t))
  264. #endif
  265.  
  266. #define TermVector(name, s)    LocalArray(Word, name, s)
  267.  
  268. #if HAVE_SIGNAL
  269. #define MAXSIGNAL        32    /* highest system signal number */
  270.  
  271. typedef RETSIGTYPE (*handler_t)(int);
  272. typedef void *SignalContext;        /* struct sigcontext on sun */
  273.  
  274. typedef struct
  275. { handler_t os;                /* Os signal handler */
  276.   handler_t user;            /* User signal handler */
  277.   bool catched;                /* Prolog catches this one */
  278. } sig_handler;
  279. #endif /* HAVE_SIGNAL */
  280.  
  281. #ifndef TRUE
  282. #define TRUE            1
  283. #define FALSE            0
  284. #endif
  285. #define succeed            return TRUE
  286. #define fail            return FALSE
  287. #define TRY(goal)        if ((goal) == FALSE) fail
  288.  
  289. #define CL_START        0    /* asserta */
  290. #define CL_END            1    /* assertz */
  291.  
  292. typedef void *            caddress;
  293.  
  294. #define EOS            ('\0')
  295. #define ESC            ((char) 27)
  296. #define streq(s, q)        ((strcmp((s), (q)) == 0))
  297.  
  298. #ifndef abs
  299. #define abs(x)            ((x) < 0 ? -(x) : (x))
  300. #endif
  301.                 /* n is 2^m !!! */
  302. #define ROUND(p, n)        ((((p) + (n) - 1) & ~((n) - 1)))
  303. #define addPointer(p, n)    ((Void) ((char *)(p) + (long)(n)))
  304. #define diffPointers(p1, p2)    ((char *)(p1) - (char *)(p2))
  305.  
  306. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  307.                  LIMITS
  308.  
  309. Below are some arbitrary limits on object sizes.  Feel free  to  enlarge
  310. them.  Descriptions:
  311.  
  312.     * LINESIZ
  313.     Buffer used to store textual info.  It is not concerned with
  314.     critical things, just things like building an error message,
  315.     reading a command for the tracer, etc.
  316.  
  317.     * MAXARITY
  318.     Maximum arity of a predicate.  May be enarged further, but
  319.     wastes stack (4 bytes for each argument) on machines that
  320.     use malloc() for allocating the stack as the local and global
  321.     stack need to be apart by this amount.  Also, an interrupt
  322.     skips this amount of stack.
  323.     
  324.     * MAXVARIABLES
  325.     Maximum number of variables in a clause.  May be increased
  326.     further, but the global local stacks need to be separated
  327.     by this amount for the segmentation-fault based stack expansion
  328.     version (just costs virtual memory).
  329. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  330.  
  331. #define BUFFER_RING_SIZE     4    /* foreign buffer ring (pl-fli.c) */
  332. #define LINESIZ            1024    /* size of a data line */
  333. #define MAXARITY        1024    /* arity of predicate */
  334. #define MAXVARIABLES        65536    /* number of variables/clause */
  335. #define OP_MAXPRIORITY        1200    /* maximum operator priority */
  336. #define SMALLSTACK        200 * 1024 /* GC policy */
  337.  
  338. #define WORDBITSIZE        (8 * sizeof(word))
  339. #define LONGBITSIZE        (8 * sizeof(long))
  340. #define INTBITSIZE        (8 * sizeof(int))
  341.  
  342.                 /* Prolog's integer range */
  343. #define PLMINTAGGEDINT        (-(long)(1L<<(WORDBITSIZE - LMASK_BITS - 1)))
  344. #define PLMAXTAGGEDINT        (-PLMINTAGGEDINT - 1)
  345. #define inTaggedNumRange(n)    (((n)&~PLMAXTAGGEDINT) == 0 || \
  346.                  ((n)&~PLMAXTAGGEDINT) == ~PLMAXTAGGEDINT)
  347. #define PLMININT        ((long)(1L<<(WORDBITSIZE-1)))
  348. #define PLMAXINT        (-(PLMININT+1))
  349.  
  350. #if vax
  351. #define MAXREAL            (1.701411834604692293e+38)
  352. #else                    /* IEEE double */
  353. #define MAXREAL            (1.79769313486231470e+308)
  354. #endif
  355.  
  356. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  357. Allocation Parameters
  358. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  359.  
  360. #define ALLOCSIZE    (1<<15)    /* size of allocation chunks (64K) */
  361. #define ALLOCFAST    512    /* big enough for all structures */
  362.  
  363. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  364. Macros to handle hash tables.  See pl-table.c for  details.   First  the
  365. sizes  of  the  hash  tables are defined.  Note that these should all be
  366. 2^N.
  367. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  368.  
  369. #define ATOMHASHSIZE        1024    /* global atom table */
  370. #define FUNCTORHASHSIZE        512    /* global functor table */
  371. #define PROCEDUREHASHSIZE    256    /* predicates in module user */
  372. #define MODULEPROCEDUREHASHSIZE 16    /* predicates in other modules */
  373. #define RECORDHASHSIZE        16    /* global recorda/recordz table */
  374. #define MODULEHASHSIZE        16    /* global module table */
  375. #define PUBLICHASHSIZE        8    /* Module export table */
  376. #define OPERATORHASHSIZE    32    /* global operator table */
  377. #define FLAGHASHSIZE        16    /* global flag/3 table */
  378. #define ARITHHASHSIZE        16    /* arithmetic function table */
  379.  
  380. #define stringHashValue(s, n) (unboundStringHashValue(s) & ((n)-1))
  381. #define pointerHashValue(p, size) ((((long)(p) >> LMASK_BITS) ^ \
  382.                     ((long)(p) >> (LMASK_BITS+5)) ^ \
  383.                     ((long)(p))) & \
  384.                    ((size)-1))
  385.  
  386. #define TABLE_REF_MASK        0x1L
  387. #define isTableRef(p)        ((unsigned long)(p) & TABLE_REF_MASK)
  388. #define makeTableRef(p)        ((void*)((unsigned long)(p) | TABLE_REF_MASK))
  389. #define unTableRef(s, p)    (*((s*)((unsigned long)(p) & ~TABLE_REF_MASK)))
  390.  
  391. #define for_table(s, t) for(s = firstHTable(t); s; s = nextHTable(t, s))
  392. #define return_next_table(t, v, clean) \
  393.     { for((v) = (v)->next; isTableRef(v) && (v); (v) = unTableRef(t, v)) \
  394.       if ( (v) == (t)NULL ) \
  395.       { clean; \
  396.         succeed; \
  397.       } \
  398.       ForeignRedoPtr(v); \
  399.     }
  400.  
  401. /* Definition->indexPattern is set to NEED_REINDEX if the definition's index
  402.    pattern needs to be recomputed */
  403. #define NEED_REINDEX ((unsigned long)1L << (LONGBITSIZE-1))
  404.  
  405. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  406. Foreign language interface definitions.  Note that these macros MUST  be
  407. consistent  with  the  definitions  in  pl-itf.h, which is included with
  408. users foreign language code.
  409. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  410.  
  411. #define FRG_CONTROL_MASK    0x00000003L
  412. #define FRG_CONTROL_BITS    2
  413.  
  414. #define FRG_FIRST_CALL    (0)        /* Initial call */
  415. #define FRG_CUTTED    (1)        /* Context was cutted */
  416. #define FRG_REDO    (2)        /* Normal redo */
  417.  
  418. #define FIRST_CALL    (0L)
  419.  
  420. #define ForeignRedoIntVal(v)    (((unsigned long)(v)<<FRG_CONTROL_BITS)|FRG_REDO)
  421. #define ForeignRedoPtrVal(v)    (((unsigned long)(v))|FRG_REDO)
  422.  
  423. #define ForeignRedoInt(v)    return ForeignRedoIntVal(v)
  424. #define ForeignRedoPtr(v)    return ForeignRedoPtrVal(v)
  425.  
  426. #define ForeignControl(h)    ((h) & FRG_CONTROL_MASK)
  427. #define ForeignContextInt(h)    ((long)(h)>>FRG_CONTROL_BITS)
  428. #define ForeignContextPtr(h)    ((void*)((unsigned long)(h)&~FRG_CONTROL_MASK))
  429.  
  430. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  431. Virtual machine instruction declarations.  Prefixes:
  432.  
  433.   I_    General instructions
  434.   B_    Body specific version
  435.   H_    Head specific versin
  436.   A_    Arithmetic compilation specific
  437.   C_    Control (compilation of ;/2, etc.)
  438.  
  439. Numbering these things is arbitrary,  but  for  fast  operation  of  the
  440. switch  in  pl-wam.c,  numbering  should start at 0 and be without gaps.
  441. I_HIGHEST must be made equal to the highest  value  of  the  instruction
  442. codes.
  443. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  444.  
  445. #define I_NOP        ((code) 0)        /* nop */
  446. #define I_ENTER        ((code) 1)        /* enter body */
  447. #define I_CALL        ((code) 2)        /* call procedure */
  448. #define I_DEPART    ((code) 3)        /* last call of procedure */
  449. #define I_EXIT        ((code) 4)        /* exit procedure */
  450. #define B_FUNCTOR    ((code) 5)        /* start functor */
  451. #define B_RFUNCTOR    ((code) 6)        /* start functor */
  452. #define H_FUNCTOR    ((code) 7)
  453. #define H_RFUNCTOR    ((code) 8)
  454. #define I_POPF        ((code) 9)        /* end functor */
  455. #define B_VAR        ((code)10)        /* variable */
  456. #define H_VAR        ((code)11)
  457. #define B_CONST        ((code)12)        /* constant (atomic) */
  458. #define H_CONST        ((code)13)
  459. #define H_INDIRECT    ((code)14)        /* indirect in the head */
  460. #define B_INTEGER    ((code)15)        /* bignum in the head */
  461. #define H_INTEGER    ((code)16)        /* bignum in the body */
  462. #define B_FLOAT        ((code)17)        /* double in the head */
  463. #define H_FLOAT        ((code)18)        /* double in the body */
  464.  
  465. #define B_FIRSTVAR    ((code)19)        /* first occurrence of var */
  466. #define H_FIRSTVAR    ((code)20)
  467. #define B_VOID        ((code)21)        /* anonimous variables */
  468. #define H_VOID        ((code)22)
  469. #define B_ARGFIRSTVAR    ((code)23)        /* body vars nested in funct */
  470. #define B_ARGVAR    ((code)24)
  471.  
  472. #define H_NIL        ((code)25)        /* [] in the head */
  473. #define B_NIL        ((code)26)        /* [] in the body */
  474. #define H_LIST        ((code)27)        /* ./2 in the head */
  475. #define H_RLIST        ((code)28)        /* right-recursive list */
  476. #define B_LIST        ((code)29)        /* ./2 in the body */
  477. #define B_RLIST        ((code)30)        /* right-recursive list */
  478.  
  479. #define B_VAR0        ((code)31)        /* B_VAR 0 */
  480. #define B_VAR1        ((code)32)        /* B_VAR 1 */
  481. #define B_VAR2        ((code)33)        /* B_VAR 2 */
  482.  
  483. #define I_USERCALL0    ((code)34)        /* variable in body (call/1) */
  484. #define I_USERCALLN    ((code)35)        /* call/[2...] */
  485. #define I_CUT        ((code)36)        /* ! */
  486. #define I_APPLY        ((code)37)        /* apply/2 */
  487.  
  488. #if O_COMPILE_ARITH
  489. #define A_ENTER        ((code)38)        /* start arithmetic sequence */
  490. #define A_INTEGER    ((code)39)        /* 32-bit signed int */
  491. #define A_DOUBLE    ((code)40)        /* 64-bit double */
  492. #define A_VAR0        ((code)41)        /* variable-0 */
  493. #define A_VAR1        ((code)42)        /* variable-1 */
  494. #define A_VAR2        ((code)43)        /* variable-2 */
  495. #define A_VAR        ((code)44)        /* variable-n */
  496. #define A_FUNC0        ((code)45)        /* nullary arithmic function */
  497. #define A_FUNC1        ((code)46)        /* unary arithmic function */
  498. #define A_FUNC2        ((code)47)        /* binary arithmic function */
  499. #define A_FUNC        ((code)48)        /* n-ary arithmic function */
  500. #define A_LT        ((code)49)        /* < */
  501. #define A_GT        ((code)50)        /* > */
  502. #define A_LE        ((code)51)        /* =< */
  503. #define A_GE        ((code)52)        /* >= */
  504. #define A_EQ        ((code)53)        /* =:= */
  505. #define A_NE        ((code)54)        /* =\= */
  506. #define A_IS        ((code)55)        /* is */
  507. #endif /* O_COMPILE_ARITH */
  508.  
  509. #if O_COMPILE_OR
  510. #define C_OR        ((code)56)        /* In-clause backtract point */
  511. #define C_JMP        ((code)57)        /* Jump over code */
  512. #define C_MARK        ((code)58)        /* Sub-clause cut mark */
  513. #define C_CUT        ((code)59)        /* cut to corresponding mark */
  514. #define C_IFTHENELSE    ((code)60)        /* if-then-else start */
  515. #define C_VAR        ((code)61)        /* make a variable */
  516. #define C_END        ((code)62)        /* dummy to help decompiler */
  517. #define C_NOT        ((code)63)        /* same as C_IFTHENELSE */
  518. #define C_FAIL        ((code)64)        /* fail */
  519. #endif /* O_COMPILE_OR */
  520.  
  521. #define B_INDIRECT    ((code)65)        /* INDIRECT in body */
  522.  
  523. #if O_BLOCK
  524. #define I_CUT_BLOCK    ((code)66)        /* !(block) */
  525. #define B_EXIT        ((code)67)        /* exit(block, rval) */
  526. #endif /*O_BLOCK*/
  527.  
  528. #if O_INLINE_FOREIGNS
  529. #define I_CALL_FV0    ((code)68)        /* call foreign, no args */
  530. #define I_CALL_FV1    ((code)69)        /* call foreign, 1 var arg */
  531. #define I_CALL_FV2    ((code)70)        /* call foreign, 2 var args */
  532. #endif /*O_INLINE_FOREIGNS*/
  533.  
  534. #define I_FAIL        ((code)71)        /* fail */
  535. #define I_TRUE        ((code)72)        /* true */
  536.  
  537. #ifdef O_SOFTCUT
  538. #define C_SOFTIF    ((code)73)        /* Start A *-> B ; C */
  539. #define C_SOFTCUT    ((code)74)        /* `Cut' of A *-> B ; C */
  540. #endif /*O_SOFTCUT*/
  541.  
  542. #define I_EXITFACT    ((code)75)        /* exit from a fact */
  543. #define D_BREAK        ((code)76)        /* Debugger break-point */
  544.  
  545. #if O_CATCHTHROW
  546. #define B_THROW        ((code)77)        /* throw(Exception) */
  547. #endif
  548.  
  549. #define I_HIGHEST    ((code)77)        /* largest WAM code !!! */
  550.  
  551. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  552. Arithmetic comparison
  553. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  554.  
  555. #define LT 1
  556. #define GT 2
  557. #define LE 3
  558. #define GE 4
  559. #define NE 5
  560. #define EQ 6
  561.  
  562. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  563. Operator types
  564. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  565.  
  566. #define    OP_FX    0
  567. #define OP_FY    1
  568. #define OP_XF    2
  569. #define OP_YF    3
  570. #define OP_XFX    4
  571. #define OP_XFY    5
  572. #define OP_YFX    6
  573. #define    OP_YFY    7
  574.  
  575. #define OP_PREFIX  1
  576. #define OP_INFIX   2
  577. #define OP_POSTFIX 3
  578.  
  579. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  580. Files and streams.  Don't change the numbers, or change FOPENMODE below.
  581. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  582.  
  583. #define F_CLOSED    0        /* closed entry */
  584. #define F_READ        1        /* open for reading */
  585. #define F_WRITE        2        /* open for writing */
  586. #define F_APPEND    3        /* open for append writing */
  587. #define F_WRNOTRUNC    4        /* open for write without truncate */
  588. #define F_ANY        5        /* any mode (finding stream) */
  589.  
  590. #define FOPENMODE "-rwau"        /* Sopen_file() mode argument */
  591.  
  592. #define streamOutput(stream, goal) \
  593.     { int SOn = streamNo(stream, F_WRITE); \
  594.       int SOout = Output; \
  595.       word SOrval; \
  596.       if ( SOn < 0 ) fail; \
  597.       Output = SOn; \
  598.       LockStream(); \
  599.       SOrval = goal; \
  600.       UnlockStream(); \
  601.       Output = SOout; \
  602.       return SOrval; \
  603.     }
  604.  
  605. #define streamInput(stream, goal) \
  606.     { int SOn = streamNo(stream, F_READ); \
  607.       int SOin = Input; \
  608.       word SOrval; \
  609.       if ( SOn < 0 ) fail; \
  610.       Input = SOn; \
  611.       SOrval = goal; \
  612.       Input = SOin; \
  613.       return SOrval; \
  614.     }
  615.  
  616. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  617. Type fields.  These codes are  included  in  a  number  of  the  runtime
  618. structures  at  a  fixed  point, so the runtime environment can tell the
  619. difference.
  620. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  621.  
  622. #define HeapMagic(n)    ((n) | 0x25678000)
  623. #define PROCEDURE_TYPE    HeapMagic(1)    /* a procedure */
  624. #define RECORD_TYPE    HeapMagic(2)    /* a record list */
  625. #define StackMagic(n)    ((n) | 0x98765000)
  626. #define QID_MAGIC    StackMagic(1)    /* Query frame */
  627.  
  628. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  629.               PROLOG DATA REPRESENTATION
  630.  
  631. Prolog data objects live on various places:
  632.  
  633.     - In the variable and argument slots of environment frames.
  634.     - As arguments to complex terms on the global stack.
  635.     - In records (recorda/recorded database) in the heap.
  636.     - In variables in foreign language functions.
  637.  
  638. All Prolog data is packed into a `word'.  A word is  a  32  bit  entity.
  639. The top 3 bits are used to indicate the type; the bottom 2 bits are used
  640. for  the  garbage  collector.   The  bits  for the garbage collector are
  641. always 0 during normal execution.  This implies we do not have  to  care
  642. about  them  for  pointers  and  as  pointers  always  point  to 4 bytes
  643. entities, the range is not harmed by the garbage collection bits.
  644.  
  645. The remaining 27 bits can hold a  unique  representation  of  the  value
  646. itself  or  can be a pointer to the global stack where the real value is
  647. stored.  We call the latter type of data `indirect'.
  648.  
  649. Below is a description of the  representation  used  for  each  type  of
  650. Prolog data:
  651.  
  652. INTEGER
  653.     Integers are stored in the  27  remaining  bits  of  a  word.   This
  654.     implies they are limited to +- 2^26.
  655. REAL
  656.     For a real, the 27 bits are a pointer to a 8 byte unit on the global
  657.     stack.  For both words of the 8 byte unit, the top 3  and  bottom  2
  658.     bits  are  reserved  for identification and garbage collection.  The
  659.     remaining bits hold the exponent and mantisse.  See pack_real()  and
  660.     unpack_real() in pl-alloc.c for details.
  661. ATOM
  662.     For atoms, the 27 bits represent a pointer  to  an  atom  structure.
  663.     Atom  structures are cells of a hash table.  Equality of the pointer
  664.     implies equality of the atoms and visa versa.  Atom  structures  are
  665.     not  collected by the garbage collector and thus live for the entire
  666.     Prolog session.
  667. STRING
  668.     For a string, the 27 bits are a pointer to the  global  stack.   The
  669.     first  word  of  the  string  again reserves  the top 3 and bottom 2
  670.     bits.  The remaining bits indicate the lenght of the  string.   Next
  671.     follows a 0 terminated character string.  Finally a word exactly the
  672.     same  as the header word, to allow the garbage collector to traverse
  673.     the stack downwards and identify the string.
  674. TERM
  675.     For a compound term, the 27 bits are a pointer to the global  stack.
  676.     the  first  word there is a pointer to a functordef structure, which
  677.     determines the name and arity of the  term.   functordef  structures
  678.     are  cells  of  a hash table like atom structures.  They to live for
  679.     the entire Prolog session.  Next, there are just as  many  words  as
  680.     the  arity  of the term, each word representing a normal Prolog data
  681.     object.
  682. VARIABLES
  683.     An unbound variable is represented by NULL.
  684. REFERENCES
  685.     References are the result of sharing variables.   If  two  variables
  686.     must  share,  the one with the shortest livetime is made a reference
  687.     pointer to the other.  This way a tree of reference pointers can  be
  688.     constructed.   The root of the tree is the variable with the longest
  689.     livetime.  To bind the entire tree of variables this root is  bound.
  690.     The  others remain reference pointers.  This implies that ANY prolog
  691.     data object might be a reference  pointer  to  another  Prolog  data
  692.     object,  holding  the  real  value.  To find the real value, a macro
  693.     called deRef() is available.
  694.  
  695.     The direction of reference pointers is critical.  It MUST  point  in
  696.     the direction of the longest living variable.  If not, the reference
  697.     pointer  will  point  into  the  dark  if  the other end dies.  This
  698.     implies that if both cells are part of an environment frame, the one
  699.     in the child function (closest to the top of the stack)  must  point
  700.     to  the  one in the parent function.  If one is on the local and one
  701.     on the global stack, the  pointer  must  point  towards  the  global
  702.     stack.   Inside  the global stack it is irrelevant.  If backtracking
  703.     destroys a variable, it also will reset the reference towards it  if
  704.     there is one.
  705. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  706.  
  707. #include "pl-data.h"
  708.  
  709. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  710. Common Prolog objects typedefs.
  711. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  712.  
  713. typedef unsigned long        term_t;        /* external term-reference */
  714. typedef unsigned long        word;        /* Anonimous 4 byte object */
  715. typedef word *            Word;        /* a pointer to anything */
  716. typedef word            atom_t;        /* encoded atom */
  717. typedef unsigned long        code;        /* bytes codes */
  718. typedef code *            Code;        /* pointer to byte codes */
  719. typedef int            Char;        /* char that can pass EOF */
  720. typedef word            (*Func)();    /* foreign functions */
  721.  
  722. typedef struct atom *        Atom;        /* atom */
  723. typedef struct functor *    Functor;    /* complex term */
  724. typedef struct functorDef *    FunctorDef;    /* name/arity pair */
  725. typedef struct procedure *    Procedure;    /* predicate */
  726. typedef struct definition *    Definition;    /* predicate definition */
  727. typedef struct clause *        Clause;        /* compiled clause */
  728. typedef struct clause_ref *    ClauseRef;      /* reference to a clause */
  729. typedef struct clause_index *    ClauseIndex;    /* Clause indexing table */
  730. typedef struct clause_chain *    ClauseChain;    /* Chain of clauses in table */
  731. typedef struct operator *    Operator;    /* see pl-op.c, pl-read.c */
  732. typedef struct record *        Record;        /* recorda/3, etc. */
  733. typedef struct recordList *    RecordList;    /* list of these */
  734. typedef struct module *        Module;        /* predicate modules */
  735. typedef struct sourceFile *    SourceFile;    /* file adminitration */
  736. typedef struct list_cell *    ListCell;    /* Anonymous list */
  737. typedef struct table *        Table;        /* (numeric) hash table */
  738. typedef struct symbol *        Symbol;        /* symbol of hash table */
  739. typedef struct localFrame *    LocalFrame;    /* environment frame */
  740. typedef struct queryFrame *    QueryFrame;     /* toplevel query frame */
  741. typedef struct fliFrame *    FliFrame;     /* FLI interface frame */
  742. typedef struct trail_entry *    TrailEntry;    /* Entry of train stack */
  743. typedef struct data_mark    mark;        /* backtrack mark */
  744. typedef struct index *        Index;        /* clause indexing */
  745. typedef struct stack *        Stack;        /* machine stack */
  746. typedef struct arithFunction *     ArithFunction;  /* arithmetic function */
  747. typedef struct assoc *        Assoc;        /* pl-bags.c */
  748. typedef struct _varDef *    VarDef;        /* pl-comp.c */
  749. typedef struct extension_cell *    ExtensionCell;  /* pl-ext.c */
  750. typedef struct abort_handle *    AbortHandle;    /* PL_abort_hook() */
  751. typedef struct initialise_handle * InitialiseHandle;
  752. typedef struct tempfile *    TempFile;     /* pl-os.c */
  753. typedef struct canonical_dir *    CanonicalDir;    /* pl-os.c */
  754. typedef struct on_halt *    OnHalt;        /* pl-os.c */
  755. typedef struct find_data_tag *    FindData;     /* pl-trace.c */
  756. typedef struct feature *    Feature;     /* pl-prims.c */
  757.  
  758.  
  759.          /*******************************
  760.          *        ARITHMETIC        *
  761.          *******************************/
  762.  
  763. typedef struct
  764. { int    type;                /* type of number */
  765.   union { real  f;            /* value as real */
  766.       long  i;            /* value as integer */
  767.       word  w[2];            /* for packing/unpacking the double */
  768.     } value;
  769. } number, *Number;
  770.  
  771. #define V_INTEGER    0        /* integer (long) value */
  772. #define V_REAL        1        /* just a real */
  773. #define V_EXPLICIT_REAL 3        /* explicely specified real */
  774.  
  775. #define intNumber(n)    ((n)->type == V_INTEGER)
  776. #define floatNumber(n)    ((n)->type & V_REAL)
  777.  
  778.          /*******************************
  779.          *       GET-PROCEDURE    *
  780.          *******************************/
  781.  
  782. #define GP_FIND        0        /* find anywhere */
  783. #define GP_FINDHERE    1        /* find in this module */
  784. #define GP_CREATE    2        /* create (in this module) */
  785. #define GP_DEFINE    4        /* define a procedure */
  786. #define GP_RESOLVE    5        /* find defenition */
  787.  
  788. #define GP_HOW_MASK    0x0ff
  789. #define GP_NAMEARITY    0x100        /* or'ed mask */
  790.  
  791.          /*******************************
  792.          *          FLAGS        *
  793.          *******************************/
  794.  
  795. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  796. Many of the structures have a large number of booleans  associated  with
  797. them.   Early  versions defined these using `unsigned <name> : 1' in the
  798. structure definition.  When I ported SWI-Prolog to a  machine  that  did
  799. not  understand  this  construct  I  decided  to pack all the flags in a
  800. short.  As this allows us to set, clear and test combinations  of  flags
  801. with one operation, it turns out to be faster as well.
  802. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  803.  
  804. #define true(s, a)        ((s)->flags & (a))
  805. #define false(s, a)        (!true((s), (a)))
  806. #define set(s, a)        ((s)->flags |= (a))
  807. #define clear(s, a)        ((s)->flags &= ~(a))
  808. #define clearFlags(s)        ((s)->flags = 0)
  809.  
  810. #define NONDETERMINISTIC    (0x00000001L) /* predicate */
  811. #define DISCONTIGUOUS        (0x00000002L) /* predicate */
  812. #define DYNAMIC            (0x00000004L) /* predicate */
  813. #define FOREIGN            (0x00000008L) /* predicate */
  814. #define HIDE_CHILDS        (0x00000010L) /* predicate */
  815. #define MULTIFILE        (0x00000020L) /* predicate */
  816. #define PROFILE_TICKED        (0x00000040L) /* predicate */
  817. #define SPY_ME            (0x00000080L) /* predicate */
  818. #define SYSTEM            (0x00000100L) /* predicate, module */
  819. #define TRACE_ME        (0x00000200L) /* predicate */
  820. #define METAPRED        (0x00000400L) /* predicate */
  821. #define GC_SAFE            (0x00000800L) /* predicate */
  822. #define TRACE_CALL        (0x00001000L) /* predicate */
  823. #define TRACE_REDO        (0x00002000L) /* predicate */
  824. #define TRACE_EXIT        (0x00004000L) /* predicate */
  825. #define TRACE_FAIL        (0x00008000L) /* predicate */
  826.                     /* This may be changed later ... */
  827. #define LOCKED            (SYSTEM)      /* predicate */
  828. #define FILE_ASSIGNED        (0x00010000L) /* predicate */
  829. #define VOLATILE        (0x00020000L) /* predicate */
  830. #define AUTOINDEX        (0x00040000L) /* predicate */
  831. #define NEEDSCLAUSEGC        (0x00080000L) /* predicate */
  832. #define NEEDSREHASH        (0x00100000L) /* predicate */
  833. #define ISCASE            (0x00200000L) /* predicate */
  834.  
  835. #define ERASED            (0x0001) /* clause */
  836. #define UNIT_CLAUSE        (0x0002) /* clause */
  837. #define HAS_BREAKPOINTS        (0x0004) /* clause */
  838.  
  839. #define UNKNOWN            (0x0002) /* module */
  840.  
  841. #define INLINE_F        (0x0001) /* functor */
  842.  
  843. #define R_DIRTY            (0x0001) /* recordlist */
  844.  
  845. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  846. Handling environment (or local stack) frames.
  847. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  848.  
  849. #define FR_LEVEL        (~0xffL)
  850. #define FR_CUT            (0x01L)
  851. #define FR_NODEBUG        (0x02L)
  852. #define FR_SKIPPED        (0x04L)
  853. #define FR_MARKED        (0x08L)
  854. #define FR_CHOICEPT        (0x10L)
  855. #define FR_WATCHED        (0x20L)
  856.  
  857. #define ARGOFFSET        ((int) sizeof(struct localFrame))
  858.  
  859. #define setLevelFrame(fr, l)    { (fr)->flags &= ~FR_LEVEL;   \
  860.                   (fr)->flags |= ((l) << 8); \
  861.                 }
  862. #define levelFrame(fr)        (fr->flags >> 8)
  863. #define incLevel(fr)        (fr->flags += 0x100)
  864. #define argFrameP(f, n)        ((Word)((f)+1) + (n))
  865. #define argFrame(f, n)        (*argFrameP((f), (n)) )
  866. #define varFrameP(f, n)        ((Word)(f) + (n))
  867. #define varFrame(f, n)        (*varFrameP((f), (n)) )
  868. #define refFliP(f, n)        ((Word)((f)+1) + (n))
  869. #define parentFrame(f)        ((f)->parent ? (f)->parent\
  870.                          : (LocalFrame)varFrame((f), -1))
  871. #define slotsFrame(f)        (true((f)->predicate, FOREIGN) ? \
  872.                       (f)->predicate->functor->arity : \
  873.                       (f)->clause->clause->prolog_vars)
  874. #define contextModule(f)    ((f)->context)
  875.  
  876. #if O_DEBUG
  877. #define enterDefinition(def)    { def->references++; }
  878. #define leaveDefinition(def)    { if ( --def->references == 0 && \
  879.                        true(def, NEEDSCLAUSEGC) ) \
  880.                     gcClausesDefinition(def); \
  881.                   if ( def->references < 0 ) \
  882.                   { Sdprintf("%s: reference count < 0\n", \
  883.                          predicateName(def)); \
  884.                     def->references = 0; \
  885.                   } \
  886.                 }
  887. #else /*O_DEBUG*/
  888. #define enterDefinition(def)    { def->references++; }
  889. #define leaveDefinition(def)    { if ( --def->references == 0 && \
  890.                        true(def, NEEDSCLAUSEGC) ) \
  891.                     gcClausesDefinition(def); \
  892.                 }
  893. #endif /*O_DEBUG*/
  894.  
  895. #ifdef O_DEBUGGER
  896. #define leaveFrame(fr) { if ( true(fr->predicate, FOREIGN) ) \
  897.              { if ( true(fr->predicate, NONDETERMINISTIC) ) \
  898.                  leaveForeignFrame(fr); \
  899.              } else \
  900.                leaveDefinition(fr->predicate); \
  901.              if ( true(fr, FR_WATCHED) ) \
  902.                frameFinished(fr); \
  903.                }
  904. #else /*O_DEBUGGER*/
  905. #define leaveFrame(fr) { if ( true(fr->predicate, FOREIGN) ) \
  906.              { if ( true(fr->predicate, NONDETERMINISTIC) ) \
  907.                  leaveForeignFrame(fr); \
  908.              } else \
  909.                leaveDefinition(fr->predicate); \
  910.                }
  911. #endif /*O_DEBUGGER*/
  912.  
  913. #define INVALID_TRAILTOP  ((word)~0L)
  914. #define INVALID_GLOBALTOP ((word)~1L)
  915.  
  916. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  917. Heuristics functions to determine whether an integer reference passed to
  918. erase and assert/2, clause/3, etc.  really points to a clause or record.
  919. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  920.  
  921. #define inCore(a)    ((char *)(a) >= hBase && (char *)(a) <= hTop)
  922. #define isProcedure(w)    (((Procedure)(w))->type == PROCEDURE_TYPE)
  923. #define isRecordList(w)    (((RecordList)(w))->type == RECORD_TYPE)
  924. #define isClause(c)    (inCore(((Clause)(c))->procedure) && \
  925.               isProcedure(((Clause)(c))->procedure))
  926. #define isRecord(r)    (inCore(((Record)(r))->list) && \
  927.               isRecordList(((Record)(r))->list))
  928.  
  929. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  930. At times an abort is not allowed because the heap  is  inconsistent  the
  931. programmer  should  call  startCritical  to start such a code region and
  932. endCritical to end it.
  933. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  934.  
  935. #define startCritical (void)(GD->critical++)
  936. #define endCritical   if ( --(GD->critical) == 0 && LD->aborted ) \
  937.             pl_abort()
  938.  
  939. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  940. LIST processing macros.
  941.  
  942.     isNil(w)        word is the nil list ([]).
  943.     isList(w)        word is a './2' term.
  944.     HeadList(p)        Pointer to the head of list *p (NOT dereferenced).
  945.     TailList(p)        Pointer to the tail of list *p (NOT dereferenced).
  946. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  947.  
  948. #define HeadList(p)    (argTermP(*(p), 0) )
  949. #define TailList(p)    (argTermP(*(p), 1) )
  950.  
  951. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  952. Structure declarations that must be shared across multiple files.
  953. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  954.  
  955. struct atom
  956. { Atom        next;        /* next in chain */
  957.   word        atom;        /* as appearing on the global stack */
  958. #ifdef O_HASHTERM
  959.   int        hash_value;    /* hash-key value */
  960. #endif
  961.   char *    name;        /* name associated with atom */
  962. };
  963.  
  964. struct index
  965. { unsigned long key;        /* key of index */
  966.   unsigned long varmask;    /* variable field mask */
  967. };
  968.  
  969. struct functorDef
  970. { FunctorDef    next;        /* next in chain */
  971.   word        functor;    /* as appearing on the global stack */
  972.   word        name;        /* Name of functor */
  973.   int        arity;        /* arity of functor */
  974.   unsigned short    flags;    /* Flag field holding: */
  975.         /* INLINE_F       Inlined foreign (system) predicate */
  976. };
  977.  
  978. struct clause
  979. { Procedure    procedure;    /* procedure we belong to */
  980.   Code        codes;        /* byte codes of clause */
  981.   struct index    index;        /* index key of clause */
  982.   short        code_size;    /* size of byte code array */
  983.   short        variables;        /* # of variables for frame */
  984.   short        prolog_vars;        /* # real Prolog variables */
  985.   unsigned short    line_no;    /* Source line-number */
  986.   unsigned short    source_no;    /* Index of source-file */
  987.   unsigned short    flags;        /* Flag field holding: */
  988.         /* ERASED       Clause is retracted, but referenced */
  989. };
  990.  
  991. struct clause_ref
  992. { Clause    clause;
  993.   ClauseRef    next;
  994. };
  995.  
  996. #define CA1_PROC    1    /* code arg 1 is procedure */
  997. #define CA1_FUNC    2    /* code arg 1 is functor */
  998. #define CA1_DATA    3    /* code arg 2 is prolog data */
  999. #define CA1_INTEGER    4    /* long value */
  1000. #define CA1_FLOAT    5    /* next 2 are double */
  1001. #define CA1_STRING    6    /* inlined string */
  1002.  
  1003. typedef struct
  1004. { char        *name;        /* name of the code */
  1005.   code        code;        /* number of the code */
  1006.   char        arguments;    /* # arguments code takes */
  1007.   char        argtype;    /* # `external' arguments code takes */
  1008. } code_info;
  1009.  
  1010. struct data_mark
  1011. { word        trailtop;    /* top of the trail stack */
  1012.   word        globaltop;    /* top of the global stack */
  1013. };
  1014.  
  1015. struct functor
  1016. { word        definition;    /* Tagged definition pointer */
  1017.   word        arguments[1];    /* arguments vector */
  1018. };
  1019.  
  1020. struct operator
  1021. { Operator    next;        /* next of chain */
  1022.   atom_t    name;        /* name of operator */
  1023.   short        type;        /* OP_FX, ... */
  1024.   short        priority;    /* priority of operator */
  1025. };
  1026.  
  1027. struct procedure
  1028. { Definition    definition;    /* definition of procedure */
  1029.   int        type;        /* PROCEDURE_TYPE */
  1030. };
  1031.  
  1032. struct clause_index
  1033. { int        buckets;        /* # entries */
  1034.   int        size;            /* # elements (clauses) */
  1035.   int        alldirty;        /* all chains need checked */
  1036.   ClauseChain     entries;        /* chains holding the clauses */
  1037. };
  1038.  
  1039. struct clause_chain
  1040. { ClauseRef    head;
  1041.   ClauseRef    tail;
  1042.   int        dirty;            /* # of garbage clauses */
  1043. };
  1044.  
  1045. struct definition
  1046. { FunctorDef    functor;        /* Name/Arity of procedure */
  1047.   union
  1048.   { ClauseRef    clauses;        /* clause list of procedure */
  1049.     Func    function;        /* function pointer of procedure */
  1050.   } definition;
  1051.   ClauseRef    lastClause;        /* last clause of list */
  1052.   Module    module;            /* module of the predicate */
  1053.   int        references;        /* reference count */
  1054. #ifdef O_PROFILE
  1055.   int        profile_ticks;        /* profiler: call times active */
  1056.   int        profile_calls;        /* profiler: number of calls */
  1057.   int        profile_redos;        /* profiler: number of redos */
  1058.   int        profile_fails;        /* profiler: number of fails */
  1059. #endif /* O_PROFILE */
  1060.   ClauseIndex     hash_info;        /* clause hash-tables */
  1061.   unsigned long indexPattern;        /* indexed argument pattern */
  1062.   unsigned long    flags;            /* booleans: */
  1063.         /*    FOREIGN           foreign predicate? */
  1064.         /*    PROFILE_TICKED       has been ticked this time? */
  1065.         /*    TRACE_ME       is my call visible? */
  1066.         /*    HIDE_CHILDS       hide childs for the debugger? */
  1067.         /*    SPY_ME           spy point set? */
  1068.         /*    DYNAMIC           dynamic predicate? */
  1069.         /*    MULTIFILE       defined over more files? */
  1070.         /*    SYSTEM           system predicate */
  1071.         /*    METAPRED       procedure transparent to modules */
  1072.         /*    DISCONTIGUOUS       procedure might be discontiguous */
  1073.         /*    NONDETERMINISTIC   deterministic foreign (not used) */
  1074.         /*    GC_SAFE           Save to perform GC while active */
  1075.         /*    TRACE_CALL       Trace call-port */
  1076.         /*    TRACE_REDO       Trace redo-port */
  1077.         /*    TRACE_EXIT       Trace exit-port */
  1078.         /*    TRACE_FAIL       Trace fail-port */
  1079.         /*    VOLATILE       Don't save my clauses */
  1080.         /*    AUTOINDEX       Automatically guess index */
  1081.         /*    NEEDSCLAUSEGC       Clauses have been erased */
  1082.         /*    NEEDSREHASH       Hash-table is out-of-date */
  1083.         /*    ISCASE           Unused.  What is this? */
  1084.   unsigned    indexCardinality : 8;    /* cardinality of index pattern */
  1085.   short        number_of_clauses;    /* number of associated clauses */
  1086. };
  1087.  
  1088. struct localFrame
  1089. { Code        programPointer;    /* pointer into program */
  1090.   LocalFrame    parent;        /* parent local frame */
  1091.   ClauseRef    clause;        /* Current clause of frame */
  1092.   LocalFrame    backtrackFrame;    /* Frame for backtracking */
  1093.   Definition    predicate;    /* Predicate we are running */
  1094.   mark        mark;        /* data backtrack mark */
  1095.   Module    context;    /* context module of frame */
  1096.   unsigned long flags;        /* packet long holding: */
  1097.         /*    LEVEL       recursion level (28 bits) */
  1098.         /*    FR_CUT     has frame been cut ? */
  1099.         /*    FR_NODEBUG don't debug this frame ? */
  1100. };  
  1101.  
  1102.  
  1103. #define QF_NODEBUG        0x0001    /* debug-able query */
  1104. #define QF_DETERMINISTIC    0x0002    /* deterministic success */
  1105. #define    QF_INTERACTIVE        0x0004    /* interactive goal (prolog()) */
  1106.  
  1107. struct queryFrame
  1108. { long        magic;            /* Magic code for security */
  1109. #if O_SHIFT_STACKS
  1110.   struct                /* Interpreter registers */
  1111.   { LocalFrame  fr;
  1112.     LocalFrame  bfr;
  1113.   } registers;
  1114. #endif
  1115. #ifdef O_LIMIT_DEPTH
  1116.   long        saved_depth_limit;    /* saved values of these */
  1117.   long        saved_depth_reached;
  1118. #endif
  1119. #if O_CATCHTHROW
  1120.   term_t    exception;        /* Exception term */
  1121. #endif
  1122.   unsigned long    flags;
  1123.   int        debugSave;        /* saved debugstatus.debugging */
  1124.   Word           *aSave;            /* saved argument-stack */
  1125.   int        solutions;        /* # of solutions produced */
  1126.   LocalFrame    bfr;            /* BacktrackFrame */
  1127.   LocalFrame    saved_environment;    /* Parent local-frame */
  1128.   struct localFrame frame;        /* The local frame */
  1129. };
  1130.  
  1131.  
  1132. struct fliFrame
  1133. { int        size;            /* # slots on it */
  1134.   FliFrame    parent;            /* parent FLI frame */
  1135.   mark        mark;            /* data-stack mark */
  1136. };
  1137.  
  1138. struct record
  1139. { RecordList    list;            /* list I belong to */
  1140.   Record    next;            /* next of chain */
  1141.   int        nvars;            /* # variables in the term */
  1142.   int        gsize;            /* Stack space required (words) */
  1143.   int        size;            /* # bytes of the record */
  1144.   int        erased;            /* record has been erased */
  1145.   char         buffer[1];        /* array holding codes */
  1146. };
  1147.  
  1148. struct recordList
  1149. { RecordList    next;        /* next record chain with same key */
  1150.   int        type;        /* RECORD_TYPE */
  1151.   int        references;    /* choicepoints reference count */
  1152.   word        key;        /* key of record */
  1153.   Record    firstRecord;    /* first record associated with key */
  1154.   Record    lastRecord;    /* last record associated with key */
  1155.   unsigned int  flags;        /* R_DIRTY */
  1156. };
  1157.  
  1158. struct sourceFile
  1159. { atom_t    name;        /* name of source file */
  1160.   SourceFile    next;        /* next of chain */
  1161.   int        count;        /* number of times loaded */
  1162.   long        time;        /* load time of file */
  1163.   ListCell    procedures;    /* List of associated procedures */
  1164.   Procedure    current_procedure;    /* currently loading one */
  1165.   int        index;        /* index number (1,2,...) */
  1166.   bool        system;        /* system sourcefile: do not reload */
  1167. };
  1168.  
  1169.  
  1170. struct list_cell
  1171. { void *    value;        /* object in the cell */
  1172.   ListCell    next;        /* next in chain */
  1173. };
  1174.  
  1175.  
  1176. struct module
  1177. { word        name;        /* name of module */
  1178.   SourceFile    file;        /* file from which module is loaded */
  1179.   Table        procedures;    /* predicates associated with module */
  1180.   Table        public;        /* public predicates associated */
  1181.   Module    super;        /* Import predicates from here */
  1182.   unsigned short flags;        /* booleans: */
  1183.         /*    SYSTEM       system module */
  1184.         /*    UNKNOWN       trap unknown predicates */
  1185. };
  1186.  
  1187. struct trail_entry
  1188. { word        address;    /* Tagged address of the variable */
  1189. };
  1190.  
  1191. struct table
  1192. { int        buckets;    /* size of hash table */
  1193.   int        size;        /* # symbols in the table */
  1194.   int        locked;        /* locked for resize */
  1195.   Symbol    *entries;    /* array of hash symbols */
  1196. };
  1197.  
  1198. struct symbol
  1199. { Symbol    next;        /* next in chain */
  1200.   word        name;        /* name entry of symbol */
  1201.   word        value;        /* associated value with name */
  1202. };
  1203.  
  1204.  
  1205.          /*******************************
  1206.          *         MARK/UNDO        *
  1207.          *******************************/
  1208.  
  1209. #define setVar(w)        ((w) = (word) NULL)
  1210.  
  1211. #ifdef O_DESTRUCTIVE_ASSIGNMENT
  1212.  
  1213. #define Undo(b)            do_undo(&b)
  1214.  
  1215. #else /*O_DESTRUCTIVE_ASSIGNMENT*/
  1216.  
  1217. #define Undo(b)        { TrailEntry tt = tTop; \
  1218.               TrailEntry mt = valPtr2((b).trailtop, STG_TRAIL); \
  1219.               while(tt > mt) \
  1220.               { tt--; \
  1221.                 setVar(*valPtr(tt->address)); \
  1222.               } \
  1223.               tTop = tt; \
  1224.               gTop = valPtr2((b).globaltop, STG_GLOBAL); \
  1225.             }
  1226. #endif /*O_DESTRUCTIVE_ASSIGNMENT*/
  1227.  
  1228. #define Mark(b)        { (b).trailtop  = consPtr(tTop, STG_TRAIL); \
  1229.               (b).globaltop = consPtr(gTop, STG_GLOBAL); \
  1230.             }
  1231.  
  1232.  
  1233.          /*******************************
  1234.          *       FLI INTERNALS    *
  1235.          *******************************/
  1236.  
  1237. typedef unsigned long qid_t;        /* external query-id */
  1238. typedef unsigned long PL_fid_t;        /* external foreign context-id */
  1239.  
  1240. #define fid_t PL_fid_t            /* avoid AIX name-clash */
  1241.  
  1242. #define consTermRef(p)    ((Word)(p) - (Word)(lBase))
  1243. #define valTermRef(r)    (&((Word)(lBase))[r])
  1244.  
  1245. #if O_SHIFT_STACKS
  1246. #define SaveLocalPtr(s, ptr)    term_t s = consTermRef(ptr)
  1247. #define RestoreLocalPtr(s, ptr) (ptr) = (void *) valTermRef(s)
  1248. #else
  1249. #define SaveLocalPtr(s, ptr)    
  1250. #define RestoreLocalPtr(s, ptr) 
  1251. #endif
  1252.  
  1253. #define QueryFromQid(qid)    ((QueryFrame) valTermRef(qid))
  1254. #define QidFromQuery(f)        (consTermRef(f))
  1255. #define QID_EXPORT_WAM_TABLE    (qid_t)(-1)
  1256.  
  1257. #include "pl-itf.h"
  1258.  
  1259.          /*******************************
  1260.          *       OPTION LISTS        *
  1261.          *******************************/
  1262.  
  1263. #define OPT_BOOL    (0)        /* types */
  1264. #define OPT_INT        (1)
  1265. #define OPT_STRING    (2)
  1266. #define OPT_ATOM    (3)
  1267. #define OPT_TERM    (4)        /* arbitrary term */
  1268.  
  1269. #define OPT_ALL        0x1        /* flags */
  1270.  
  1271. typedef struct
  1272. { word        name;            /* Name of option */
  1273.   int        type;            /* Type of option */
  1274. } opt_spec, *OptSpec;
  1275.  
  1276.          /*******************************
  1277.          *          EVENTS        *
  1278.          *******************************/
  1279.  
  1280. #define PLEV_ERASED       0         /* clause or record was erased */
  1281. #define PLEV_DEBUGGING       1        /* changed debugging mode */
  1282. #define PLEV_TRACING       2        /* changed tracing mode */
  1283. #define PLEV_SPY       3        /* changed spypoint */
  1284. #define PLEV_BREAK       4        /* a break-point was set */
  1285. #define PLEV_NOBREAK       5        /* a break-point was cleared */
  1286. #define PLEV_FRAMEFINISHED 6        /* A watched frame was discarded */
  1287.  
  1288.  
  1289.         /********************************
  1290.         *             STACKS            *
  1291.         *********************************/
  1292.  
  1293. #ifdef small                /* defined by MSVC++ 2.0 windows.h */
  1294. #undef small
  1295. #endif
  1296.  
  1297. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1298. If we have access to the virtual   memory management of the machine, use
  1299. this to enlarge the runtime stacks.  Otherwise use the stack-shifter.
  1300. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1301.  
  1302. #define GC_FAST_POLICY 0x1        /* not really used yet */
  1303.  
  1304. #if O_SHARED_MEMORY
  1305. #define O_SHM_FREE_IMMEDIATE 1
  1306. #define MAX_STACK_SEGMENTS  20
  1307. #define STACK(type) \
  1308.     { type        base;        /* base address of the stack */     \
  1309.       type        top;        /* current top of the stack */      \
  1310.       type        max;        /* allocated maximum */            \
  1311.       long        limit;        /* how big it is allowed to grow */ \
  1312.       long        maxlimit;    /* maximum limit */                 \
  1313.       char        *name;        /* Symbolic name of the stack */    \
  1314.       long        segment_initial;/* initial size */            \
  1315.       int        segment_double;    /* times to double */            \
  1316.       int        segment_top;    /* Next segment to be allocated */  \
  1317.       struct                                \
  1318.       { caddress    base;        /* Base of this segment */        \
  1319.         long    size;        /* Size of this segment */        \
  1320.       } segments[MAX_STACK_SEGMENTS];                    \
  1321.     }
  1322. #else /* !O_SHARED_MEMORY */
  1323. #define STACK(type) \
  1324.     { type        base;        /* base address of the stack */     \
  1325.       type        top;        /* current top of the stack */      \
  1326.       type        min;        /* donot shrink below this value */ \
  1327.       type        max;        /* allocated maximum */            \
  1328.       type        limit;        /* top the the range (base+limit) */\
  1329.       long        minfree;    /* minimum amount of free space */  \
  1330.       bool        gc;        /* Can be GC'ed? */            \
  1331.       unsigned long    gced_size;    /* size after last GC */        \
  1332.       unsigned long    small;        /* Donot GC below this size */        \
  1333.       unsigned int    factor;        /* How eager we are */            \
  1334.       int        policy;        /* Time, memory optimization */        \
  1335.       char        *name;        /* Symbolic name of the stack */    \
  1336.     }
  1337. #endif
  1338.  
  1339. struct stack STACK(caddress);        /* Anonymous stack */
  1340.  
  1341. #define N_STACKS (4)
  1342.  
  1343. typedef struct
  1344. { struct STACK(LocalFrame) local;    /* local (environment) stack */
  1345.   struct STACK(Word)       global;    /* local (environment) stack */
  1346.   struct STACK(TrailEntry) trail;    /* trail stack */
  1347.   struct STACK(Word *)       argument;    /* argument stack */
  1348. } pl_stacks_t;
  1349.  
  1350. #define tBase    (LD->stacks.trail.base)
  1351. #define tTop    (LD->stacks.trail.top)
  1352. #define tMax    (LD->stacks.trail.max)
  1353.  
  1354. #define lBase    (LD->stacks.local.base)
  1355. #define lTop    (LD->stacks.local.top)
  1356. #define lMax    (LD->stacks.local.max)
  1357. #define lLimit    (LD->stacks.local.limit)
  1358.  
  1359. #define gBase    (LD->stacks.global.base)
  1360. #define gTop    (LD->stacks.global.top)
  1361. #define gMax    (LD->stacks.global.max)
  1362. #define gLimit    (LD->stacks.global.limit)
  1363.  
  1364. #define aBase    (LD->stacks.argument.base)
  1365. #define aTop    (LD->stacks.argument.top)
  1366. #define aMax    (LD->stacks.argument.max)
  1367. #define aLimit    (LD->stacks.argument.limit)
  1368.  
  1369. #define SetHTop(val)    { if ( (char *)(val) > hTop  ) hTop  = (char *)(val); }
  1370. #define SetHBase(val)    { if ( (char *)(val) < hBase ) hBase = (char *)(val); }
  1371.  
  1372. #define onStack(name, addr) \
  1373.     ((char *)(addr) >= (char *)LD->stacks.name.base && \
  1374.      (char *)(addr) <  (char *)LD->stacks.name.top)
  1375. #ifdef O_SHIFT_STACKS
  1376. #define onStackArea(name, addr) \
  1377.     ((char *)(addr) >= (char *)LD->stacks.name.base && \
  1378.      (char *)(addr) <  (char *)LD->stacks.name.max)
  1379. #else
  1380. #define onStackArea(name, addr) \
  1381.     ((char *)(addr) >= (char *)LD->stacks.name.base && \
  1382.      (char *)(addr) <  (char *)LD->stacks.name.limit)
  1383. #endif
  1384. #define usedStack(name) ((char *)LD->stacks.name.top - \
  1385.              (char *)LD->stacks.name.base)
  1386. #define sizeStack(name) ((char *)LD->stacks.name.max - \
  1387.              (char *)LD->stacks.name.base)
  1388. #define roomStack(name) ((char *)LD->stacks.name.max - \
  1389.              (char *)LD->stacks.name.top)
  1390. #define narrowStack(name) (roomStack(name) < LD->stacks.name.minfree)
  1391.  
  1392. #if O_DYNAMIC_STACKS
  1393. #ifdef NO_SEGV_HANDLING
  1394. #define requireStack(s, n) \
  1395.     { if ( roomStack(s) < (int)(n) ) \
  1396.          ensureRoomStack((Stack)&LD->stacks.s, n); \
  1397.     }
  1398. #define verifyStack(s) requireStack(s, 64)
  1399. #else /*NO_SEGV_HANDLING*/
  1400. #define requireStack(s, n)
  1401. #define verifyStack(s)
  1402. #endif /*NO_SEGV_HANDLING*/
  1403. #else
  1404. #define requireStack(s, n) \
  1405.     { if ( roomStack(s) < (n) ) \
  1406.          outOf((Stack)&LD->stacks.s); \
  1407.     }
  1408. #define verifyStack(s) requireStack(s, 64)
  1409. #endif
  1410.  
  1411.  
  1412.         /********************************
  1413.         *       READ WARNINGS           *
  1414.         *********************************/
  1415.  
  1416. #define ReadingSource (source_line_no > 0 && \
  1417.                source_file_name != NULL_ATOM)
  1418.  
  1419.  
  1420.         /********************************
  1421.         *        FAST DISPATCHING    *
  1422.         ********************************/
  1423.  
  1424. #if VMCODE_IS_ADDRESS
  1425. #define encode(wam) (wam_table[wam])        /* WAM --> internal */
  1426.                         /* internal --> WAM */
  1427. #define decode(c)   ((code) (dewam_table[(unsigned long)(c) - \
  1428.                      dewam_table_offset]))
  1429. #else /* VMCODE_IS_ADDRESS */
  1430. #define encode(wam) (wam)
  1431. #define decode(wam) (wam)
  1432. #endif /* VMCODE_IS_ADDRESS */
  1433.  
  1434.         /********************************
  1435.         *            STATUS             *
  1436.         *********************************/
  1437.  
  1438. typedef struct
  1439. { bool        requested;        /* GC is requested by stack expander */
  1440.   int        blocked;        /* GC is blocked now */
  1441.   bool        active;            /* Currently running? */
  1442.   long        collections;        /* # garbage collections */
  1443.   long        global_gained;        /* global stack bytes collected */
  1444.   long        trail_gained;        /* trail stack bytes collected */
  1445.   real        time;            /* time spent in collections */
  1446. } pl_gc_status_t;
  1447.  
  1448.  
  1449. typedef struct
  1450. { int        blocked;        /* No shifts allowed */
  1451.   real        time;            /* time spent in stack shifts */
  1452.   int        local_shifts;        /* Shifts of the local stack */
  1453.   int        global_shifts;        /* Shifts of the global stack */
  1454.   int        trail_shifts;        /* Shifts of the trail stack */
  1455. } pl_shift_status_t;
  1456.  
  1457.  
  1458. typedef struct
  1459. { atom_t    symbolfile;        /* current symbol file */
  1460.   atom_t    orgsymbolfile;        /* symbol file we started with */
  1461.   atom_t    restored_state;        /* -r/restore state restored */
  1462. } pl_loaderstatus_t;
  1463.  
  1464. #define NO_PROFILING        0
  1465. #define CUMULATIVE_PROFILING    1
  1466. #define PLAIN_PROFILING        2
  1467.  
  1468.  
  1469.         /********************************
  1470.         *            MODULES            *
  1471.         *********************************/
  1472.  
  1473. #define MODULE_user    (GD->modules.user)
  1474. #define MODULE_system    (GD->modules.system)
  1475.  
  1476.         /********************************
  1477.         *         PREDICATES            *
  1478.         *********************************/
  1479.  
  1480. #define PROCEDURE_alt1            (GD->procedures.alt1)
  1481. #define PROCEDURE_garbage_collect0    (GD->procedures.garbage_collect0)
  1482. #define PROCEDURE_block3        (GD->procedures.block3)
  1483. #define PROCEDURE_catch3        (GD->procedures.catch3)
  1484. #define PROCEDURE_true0            (GD->procedures.true0)
  1485. #define PROCEDURE_fail0            (GD->procedures.fail0)
  1486. #define PROCEDURE_event_hook1        (GD->procedures.event_hook1)
  1487. #define PROCEDURE_print_message2    (GD->procedures.print_message2)
  1488.  
  1489. extern const code_info codeTable[]; /* Instruction info (read-only) */
  1490.  
  1491.         /********************************
  1492.         *            DEBUGGER           *
  1493.         *********************************/
  1494.  
  1495. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1496. Tracer communication declarations.
  1497. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1498.  
  1499. #define ACTION_CONTINUE    0
  1500. #define ACTION_RETRY    1
  1501. #define ACTION_FAIL    2
  1502. #define ACTION_IGNORE    3
  1503. #define ACTION_AGAIN    4
  1504.  
  1505. #define CALL_PORT    0x001        /* port masks */
  1506. #define EXIT_PORT    0x002
  1507. #define FAIL_PORT    0x004
  1508. #define REDO_PORT    0x008
  1509. #define UNIFY_PORT    0x010
  1510. #define BREAK_PORT    0x020
  1511. #define CUT_CALL_PORT   0x040
  1512. #define CUT_EXIT_PORT   0x080
  1513. #define EXCEPTION_PORT    0x100
  1514. #define CUT_PORT    (CUT_CALL_PORT|CUT_EXIT_PORT)
  1515. #define VERY_DEEP    1000000000L    /* deep skiplevel */
  1516.  
  1517. #define LONGATOM_CHECK        0x1        /* read/1: error on long atoms */
  1518. #define SINGLETON_CHECK        0x2        /* read/1: check singleton vars */
  1519. #define DOLLAR_STYLE        0x4        /* dollar is lower case */
  1520. #define DISCONTIGUOUS_STYLE 0x8        /* warn on discontiguous predicates */
  1521. #if O_STRING
  1522. #define STRING_STYLE        0x10    /* read ".." as string object */
  1523. #endif /* O_STRING */
  1524. #define DYNAMIC_STYLE        0x20    /* warn on assert/retract active */
  1525. #define MAXNEWLINES        5        /* maximum number of newlines in atom */
  1526. #define SYSTEM_MODE        (debugstatus.styleCheck & DOLLAR_STYLE)
  1527.  
  1528. typedef struct debuginfo
  1529. { unsigned long    skiplevel;        /* current skip level */
  1530.   bool        tracing;        /* are we tracing? */
  1531.   bool        debugging;        /* are we debugging? */
  1532.   int        leashing;        /* ports we are leashing */
  1533.   int            visible;        /* ports that are visible */
  1534.   int        style;            /* print style of tracer */
  1535.   bool        showContext;        /* tracer shows context module */
  1536.   int        styleCheck;        /* source style checking */
  1537.   int        suspendTrace;        /* tracing is suspended now */
  1538.   LocalFrame    retryFrame;        /* Frame to retry */
  1539. } pl_debugstatus_t;
  1540.  
  1541. #define FT_ATOM        0        /* atom feature */
  1542. #define FT_INTEGER    1        /* integer feature */
  1543.  
  1544. #define CHARESCAPE_FEATURE    0x0001    /* handle \ in atoms */
  1545. #define GC_FEATURE        0x0002    /* do GC */
  1546. #define TRACE_GC_FEATURE    0x0004    /* verbose gc */
  1547. #define TTY_CONTROL_FEATURE    0x0008    /* allow for tty control */
  1548. #define READLINE_FEATURE    0x0010    /* readline is loaded */
  1549. #define DEBUG_ON_ERROR_FEATURE    0x0020    /* start tracer on error */
  1550. #define REPORT_ERROR_FEATURE    0x0040    /* print error message */
  1551. #define FILE_CASE_FEATURE    0x0080    /* file names are case sensitive */
  1552. #define FILE_CASE_PRESERVING_FEATURE 0x0100 /* case preserving file names */
  1553. #define DOS_FILE_NAMES_FEATURE  0x0200    /* dos (8+3) file names */
  1554. #define ALLOW_VARNAME_FUNCTOR    0x0400    /* Read Foo(x) as 'Foo'(x) */
  1555.  
  1556. typedef struct
  1557. { unsigned long flags;            /* the feature flags */
  1558. } pl_features_t;
  1559.  
  1560. #define trueFeature(mask)    true(&features, mask)
  1561.  
  1562. #ifdef O_LIMIT_DEPTH
  1563. #define DEPTH_NO_LIMIT    (~0x0L)        /* Highest value */
  1564. #endif
  1565.  
  1566. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1567. Administration of loaded intermediate code files  (see  pl-wic.c).  Used
  1568. with the -c option to include all these if necessary.
  1569. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1570.  
  1571. typedef struct state * State;
  1572.  
  1573. struct state
  1574. { char *    name;            /* name of state */
  1575.   State        next;            /* next state loaded */
  1576. };
  1577.  
  1578. #define QLF_TOPLEVEL 0x1        /* toplevel wic file */
  1579. #define QLF_OPTIONS  0x2        /* only load options */
  1580. #define QLF_EXESTATE 0x4        /* probe qlf exe state */
  1581.  
  1582. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1583. Sourcelocation information (should be used at more places).
  1584. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1585.  
  1586. typedef struct
  1587. { atom_t    file;            /* name of the file */
  1588.   int        line;            /* line number */
  1589. } sourceloc, *SourceLoc;
  1590.  
  1591. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1592. Include debugging info to make it (very) verbose.  SECURE adds  code  to
  1593. check  consistency mainly in the WAM interpreter.  Prolog gets VERY slow
  1594. if SECURE is  used.   DEBUG  is  not  too  bad  (about  20%  performance
  1595. decrease).
  1596. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  1597.  
  1598. #define REL(a)        ((Word)(a) - (Word)(lBase))
  1599.  
  1600. #if O_DEBUG
  1601. #define DEBUG(n, g) { if (GD->debug_level >= (n)) { g; } }
  1602. #else
  1603. #define DEBUG(a, b) 
  1604. #endif
  1605.  
  1606. #if O_SECURE
  1607. #define SECURE(g) {g;}
  1608. #else
  1609. #define SECURE(g)
  1610. #endif
  1611.  
  1612. #include "pl-os.h"            /* OS dependencies */
  1613.  
  1614. #ifdef SYSLIB_H
  1615. #include SYSLIB_H
  1616. #endif
  1617.  
  1618. #include "pl-funcs.h"            /* global functions */
  1619. #include "pl-main.h"            /* Declarations needed by pl-main.c */
  1620. #include "pl-error.h"            /* Exception generation */
  1621. #include "pl-global.h"            /* global data */
  1622.  
  1623. #define NULL_ATOM ((atom_t)0)
  1624. #define MK_ATOM(n)            ((n)<<7|TAG_ATOM|STG_STATIC)
  1625. #include "pl-atom.ih"
  1626. #include "pl-funct.ih"
  1627.  
  1628. #ifdef O_INLINE_FLI
  1629.  
  1630. #define PL_new_term_refs(n)    _PL_new_term_refs(n)
  1631. #define PL_new_term_ref()    _PL_new_term_ref()
  1632. #define PL_reset_term_refs(t)    _PL_reset_term_refs(t)
  1633.  
  1634. static inline term_t
  1635. _PL_new_term_refs(int n)
  1636. { Word t = (Word)lTop;
  1637.   term_t r = consTermRef(t);
  1638.  
  1639.   while(n-- > 0)
  1640.     setVar(*t++);
  1641.   lTop = (LocalFrame)t;
  1642.   verifyStack(local);
  1643.   
  1644.   return r;
  1645. }
  1646.  
  1647.  
  1648. static inline term_t
  1649. _PL_new_term_ref()
  1650. { Word t = (Word)lTop;
  1651.   term_t r = consTermRef(t);
  1652.  
  1653.   lTop = (LocalFrame)(t+1);
  1654.   verifyStack(local);
  1655.   setVar(*t);
  1656.   
  1657.   return r;
  1658. }
  1659.  
  1660.  
  1661. static inline void
  1662. _PL_reset_term_refs(term_t r)
  1663. { lTop = (LocalFrame) valTermRef(r);
  1664. }
  1665.  
  1666. #endif /*O_INLINE_FLI*/
  1667.  
  1668. #endif /*_PL_INCLUDE_H*/
  1669.